home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / programr / tp / percnt / ctrlflag.pas < prev    next >
Pascal/Delphi Source File  |  1991-11-11  |  3KB  |  106 lines

  1. {***************************************************************************
  2.  
  3.     NoMan Custom Control Library            $Version$
  4.     Flags Module Unit
  5.     $Author$        $Date$
  6.  
  7.         Copyright 1991 Anthony M. Vitabile
  8.  
  9.     Unit Description
  10.  
  11.     This Turbo Pascal for Windows unit contains a routine that
  12.     creates control style strings.    This routine is common to all
  13.     controls in the DLL.  It also implements one exported routine
  14.     for each type of control which calls the common routine.  This
  15.     minimizes the duplication of code in the unit.
  16.  
  17.     The library uses straight Windows calls and does NOT use Object-
  18.     Windows.  This is to allow the control to be used by ANY Windows
  19.     program.
  20.  
  21.     This code is adapted from the code that appeared in the July,
  22.     1990 issue of Microsoft Systems Journal article, "Extending the
  23.     Windows 3.0 Interface with Installable Custom Controls" by Kevin
  24.     P. Welch.  The code has been extended to support the multiple
  25.     control DLL format defined by Borland for use with their
  26.     Resource Workshop resource editor.
  27.  
  28. ***************************************************************************}
  29.  
  30. {$C DemandLoad Discardable}
  31. Unit CtrlFlags;
  32. Interface
  33.   Uses WinTypes, CustCntl;
  34.  
  35.   function PercentCtrlFlags(Style :  longint;
  36.                 Txt   :  PChar;
  37.                 MaxStr:  word
  38.                ):  word; export;
  39.  
  40. Implementation
  41.   Uses CtrlCommonDefs, Strings, WinProcs;
  42.  
  43.   type
  44.     FlagsArray    = array [1 .. 16] of PChar;
  45.     StylesArray = array [1 .. 16] of longint;
  46.  
  47.   var
  48.     PctFlags :    FlagsArray;
  49.     PctStyles:    StylesArray;
  50.  
  51.   function BuildFlags(Style :  longint;
  52.               Txt   :  PChar;
  53.               MaxStr,
  54.               NStyle:  word;
  55.           var Styles:  StylesArray;
  56.           var Flags :  FlagsArray
  57.              ):  word;
  58.     var
  59.       i   :  integer;
  60.       len :  word;
  61.  
  62.     begin    { BuildFlags }
  63.       i      := 1;
  64.       len    := 0;
  65.       Txt[0] := #0;
  66.       while (len < MaxStr) and (i <= NStyle) do
  67.     begin
  68.       if (Style and Styles[i]) <> 0
  69.        then
  70.         begin
  71.          if len > 0
  72.           then
  73.            begin
  74.         StrCat(Txt, ' | ');
  75.         len := len + 3
  76.            end;
  77.          StrCat(Txt, Flags[i]);
  78.          len := len + StrLen(Flags[i])
  79.         end;
  80.       inc(i)
  81.     end;
  82.       BuildFlags := len
  83.     end     { BuildFlags };
  84.  
  85.   function PercentCtrlFlags(Style :  longint;
  86.                 Txt   :  PChar;
  87.                 MaxStr:  word
  88.                ):  word;
  89.     begin    { PercentCtrlFlags }
  90.       PercentCtrlFlags := BuildFlags(Style, Txt, MaxStr, PctNoStyles, PctStyles, PctFlags)
  91.     end     { PercentCtrlFlags };
  92.  
  93.   begin
  94.     PctFlags [1] := 'Pct_Decades';
  95.     PctFlags [2] := 'Pct_Quarters';
  96.     PctFlags [3] := 'Pct_Halves';
  97.     PctFlags [4] := 'Pct_Axis';
  98.     PctFlags [5] := 'Pct_Digits';
  99.  
  100.     PctStyles[1] := Pct_Decades;
  101.     PctStyles[2] := Pct_Quarters;
  102.     PctStyles[3] := Pct_Halves;
  103.     PctStyles[4] := Pct_Axis;
  104.     PctStyles[5] := Pct_Digits;
  105.   end.
  106.